package org.example;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.TextStyle;
import java.util.Locale;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {
        LocalDate date = LocalDate.parse("2020-01-09");
        WeekdayPrinter printer = new WeekdayPrinter(date);

        System.out.println(printer.print());
        System.out.println(printer.print("html"));
    }

    private static class WeekdayPrinter {
        private final LocalDate date;

        public WeekdayPrinter(LocalDate date) {
            this.date = date;
        }


        public String print() {
            LocalDate firstDay = date.with(DayOfWeek.MONDAY);
            StringBuffer sb = new StringBuffer();
            for (int i = -1; i < 6; i++) {
                sb.append(String.format("%s\t", (firstDay.plusDays(i).getDayOfWeek()).getDisplayName(TextStyle.NARROW, Locale.CHINESE)));
            }
            sb.append("\n");
            for (int i = -1; i < 6; i++) {
                sb.append(String.format("%s\t", firstDay.plusDays(i).getDayOfMonth()));
            }

            return sb.toString();
        }
        public String print(String formatter) {
            LocalDate firstDay = date.with(DayOfWeek.MONDAY);
            StringBuffer sb = new StringBuffer();
            sb.append("<table>\n");
            sb.append("<thead>\n");
            sb.append("<tr>\n");
            for (int i = -1; i < 6; i++) {
                sb.append(String.format("<td>%s</td>\n", (firstDay.plusDays(i).getDayOfWeek()).getDisplayName(TextStyle.NARROW, Locale.CHINESE)));
            };
            sb.append("</tr>\n");


            sb.append("<tr>\n");
            for (int i = -1; i < 6; i++) {
                sb.append(String.format("<td>%s</td>\n", firstDay.plusDays(i).getDayOfMonth()));
            }

            sb.append("</tr>\n");
            sb.append("</table>");
            return sb.toString();
        }
    }
}
